﻿module X3D_FSharpClass
open System
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Graphics
open Component

type Box (DEF: string, Size: Vector3) = 
    let mutable myModel : Model = null
    let mutable s = Size
    member this.size
        with get () = s
        and  set (newv) = s <- newv
    member this.set_Model (newv) = myModel <- newv    
    member this.Draw (dt:float32) =
        for m in myModel.Meshes do
            for eff in m.Effects do
                let basic_effect = (eff :?> BasicEffect)
                basic_effect.EnableDefaultLighting()
                basic_effect.World <- Matrix.Identity
                basic_effect.View <- Matrix.CreateLookAt(Vector3.Backward * 10.0f, Vector3.Zero, Vector3.Up)
                basic_effect.Projection <- Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, (800.0f/600.0f), 10.0f, 1000.0f)

type ColorInterpolator (DEF: string, Key: Vector3 list, KeyValue: float32 list) =
  let mutable f = KeyValue.Head
  let mutable v = Key.Head
  member this.set_fraction
      with get () = f
      and  set (newv) = f <- newv 
  member this.value_changed
      with get () = v
      and  set (newv) = v <- newv

type Material (DEF: string, DiffuseColor: Vector3) =
  let mutable d_c = DiffuseColor
  member this.diffuseColor
      with get () = d_c
      and  set (newv) = d_c <- newv

type TimeSensor (Loop: bool, CycleInterval: float32) = 
  let mutable l =Loop
  let mutable ci = CycleInterval
  let mutable t = 0.0f
  member this.time 
      with get () = t
      and  set (newv) = t <- t + newv
  member this.fraction_changed
      with get () = (t % ci) / ci
      and  set (newv) = t <- newv

type Appearance (Material: Material) = class end
type Shape (Box: Box, Appearance: Appearance) = class end

